package vendalenger.debvi.editors;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.swing.border.TitledBorder;

import vendalenger.debvi.jfx.DebviFrame;
import vendalenger.debvi.jfx.Shortcut;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.geometry.NodeOrientation;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.Separator;
import javafx.scene.control.Tab;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

public class Welcome_Screen implements Editor {
	@Override
	public void open(String[] args) {
		Tab screen = new Tab("Welcome");
		StackPane preboard = new StackPane();
		final VBox board = new VBox();
		board.setAlignment(Pos.TOP_CENTER);
		board.getChildren().add(new Label("Do you like eggs?"));
		try {
			ImageView i = new ImageView(new Image(new FileInputStream(new File("Resource/Images/welcome.png"))));
			board.getChildren().add(i);
			board.getChildren().add(new Separator(Orientation.HORIZONTAL));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		try {
			Button ba = new Button("a", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			Button bb = new Button("b", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			Button bc = new Button("c", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			Button bd = new Button("d", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			Button be = new Button("e", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			Button bf = new Button("f", new ImageView(new Image(new FileInputStream(new File("Resource/Icons/Window/debvi32.png")))));
			ba.setPrefSize(128, 128);
			bb.setPrefSize(128, 128);
			bc.setPrefSize(128, 128);
			bd.setPrefSize(128, 128);
			be.setPrefSize(128, 128);
			bf.setPrefSize(128, 128);
			ba.setShape(Shortcut.leaf());
			bb.setShape(Shortcut.leaf());
			bc.setShape(Shortcut.leaf());
			bd.setShape(Shortcut.leaf());
			be.setShape(Shortcut.leaf());
			bf.setShape(Shortcut.leaf());
			TilePane buttons = new TilePane();
			buttons.setHgap(8);
			buttons.setVgap(8);
			buttons.setPadding(new Insets(8, 0, 8, 0));
			buttons.setMaxWidth(400);
			buttons.setPrefRows(2);
			buttons.getChildren().add(ba);
			buttons.getChildren().add(bb);
			buttons.getChildren().add(bc);
			buttons.getChildren().add(bd);
			buttons.getChildren().add(be);
			buttons.getChildren().add(bf);
			board.getChildren().add(buttons);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		board.getChildren().add(new Separator(Orientation.HORIZONTAL));
		
		WebView changelog = new WebView();
		WebEngine webEngine = changelog.getEngine();
		webEngine.load("https://debvi.googlecode.com/git/Debvi/.classpath");
		board.getChildren().add(changelog);
		
		ScrollPane sp = new ScrollPane();
		sp.setContent(board);
		sp.setHbarPolicy(ScrollBarPolicy.NEVER);
		sp.setFitToWidth(true);
		sp.setFitToHeight(true);
		preboard.getChildren().add(sp);
		
		TextArea op = new TextArea();
		TitledPane open = new TitledPane("Open Project", op);
		preboard.getChildren().add(open);
		
		preboard.setAlignment(Pos.TOP_CENTER);
		screen.setContent(preboard);
		DebviFrame.addTab(screen, "welcome_screen");
	}
}
